package com.example.yunJie.digitalSentry.mapper.one;


import com.example.yunJie.digitalSentry.entity.SchedulingEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.io.Serializable;
import java.util.List;

public interface SchedulingMapper {
//    @Insert("<script>insert into sz_scheduling(personalId,shiftId)\n" +
//            "        values(#{personalId},#{shiftId})</script>")
    int insert(SchedulingEntity schedulingEntity);

//    @Update("<script>update sz_scheduling\n" +
//            "        <trim prefix=\"SET\" suffixOverrides=\",\">\n" +
//            "            <if test=\"personalId != null and personalId != ''\">personalId = #{personalId},</if>\n" +
//            "            <if test=\"shiftId != null and shiftId != ''\">shiftId = #{shiftId},</if>\n" +
//            "\n" +
//            "        </trim>\n" +
//            "        where id = #{id}</script>")
    int update(SchedulingEntity schedulingEntity);

//    @Delete("<script> delete from sz_scheduling where id = #{Id}</script>")
    int deleteById(Serializable id);

//    @Delete("<script>delete from sz_scheduling where id in\n" +
//            "        <foreach collection=\"array\" item=\"id\" open=\"(\" separator=\",\" close=\")\">\n" +
//            "            #{id}\n" +
//            "        </foreach></script>")
    int deleteIdList(Long[] idList);

//    @Select("<script>select  personalId,shiftId\n" +
//            "        from sz_scheduling\n" +
//            "        where id = #{id}</script>")
    SchedulingEntity findId(Serializable id);

//    @Select("<script>SELECT * FROM sz_scheduling\n" +
//            "        left join sz_shift on sz_scheduling.shiftId = sz_shift.id\n" +
//            "        LEFT JOIN sz_personal on sz_personal.id = sz_scheduling.personalId\n" +
//            "        left join sz_post on sz_post.id = sz_shift.postId\n" +
//            "        LEFT JOIN sz_market on sz_shift.marketId = sz_market.id\n" +
//            "        <where>\n" +
//            "            <if test=\"postName != null and postName!= ''\"> and  sz_shift.postId = ( SELECT sz_post.id FROM sz_post where sz_post.postName = #{postName})</if>\n" +
//            "            <if test=\"marketName != null and marketName != ''\">and sz_shift.marketId = ( SELECT sz_market.id from sz_market where sz_market.marketName = #{marketName})</if>\n" +
//            "            <if test=\"shiftName != null and shiftName != ''\">  and sz_shift.shiftName = #{shiftName}</if>\n" +
//            "            <if test=\"personalId != null and personalId != ''\"> and sz_personal.id = #{personalId} </if>\n" +
//            "        </where></script>")
    List<SchedulingEntity> findAll(SchedulingEntity schedulingEntity);
//    @Select("<script>select * from sz_scheduling where personalId = #{personalId}</script>")
    SchedulingEntity findByPersonalId(String id);
//    @Select("<script>select * from sz_scheduling where shiftId = #{shiftId} and personalId = #{personalId}</script>")
    SchedulingEntity findByPersonalIdAndShiftId(SchedulingEntity schedulingEntity);

    //根据市场名称和岗位名称查找排班列表
//    @Select("<script>SELECT sz_shift.* ,sz_personal.personalName FROM sz_shift\n" +
//            "           left join sz_scheduling on sz_scheduling.shiftId = sz_shift.id\n" +
//            "           LEFT JOIN sz_personal on sz_personal.id = sz_scheduling.personalId\n" +
//            "        where  sz_shift.postId = (\n" +
//            "            SELECT sz_post.postId FROM sz_post where sz_post.postName = #{postName}\n" +
//            "        )and sz_shift.marketId = (\n" +
//            "            SELECT sz_market.marketId from sz_market where sz_market.marketName = #{marketName}\n" +
//            "        )</script>")
    List<SchedulingEntity> findAllByMarketNameAndPostName(String marketName, String postName);

    //根据市场名称查找所有排班
//    @Select("<script>SELECT sz_shift.* ,sz_personal.personalName FROM sz_shift\n" +
//            "            left join sz_scheduling on sz_scheduling.shiftId = sz_shift.id\n" +
//            "            LEFT JOIN sz_personal on sz_personal.id = sz_scheduling.personalId\n" +
//            "        where sz_shift.marketId =  (\n" +
//            "            SELECT sz_market.marketId from sz_market where sz_market.marketName = #{marketName}\n" +
//            "        )</script>")
    List<SchedulingEntity> findAllByMarketName(String marketName);

    //根据市场名，岗位名，班次名查找排班列表
//    @Select("<script>SELECT sz_shift.* , sz_scheduling.personalId FROM sz_shift\n" +
//            "              left join sz_scheduling on sz_scheduling.shiftId = sz_shift.id\n" +
//            "              LEFT JOIN sz_personal on sz_personal.id = sz_scheduling.personalId\n" +
//            "        where sz_shift.postId = (\n" +
//            "            SELECT sz_post.postId FROM sz_post where sz_post.postName = #{postName}\n" +
//            "        )and sz_shift.marketId = (\n" +
//            "            SELECT sz_market.marketId from sz_market where sz_market.marketName = #{marketName}\n" +
//            "        )and sz_shift.shiftName = #{shiftName}</script>")
    List<SchedulingEntity> findAllByMarketNameAndPostNameAndShiftName(String marketName,String postName,String shiftName);

    //根据班次名查找排班
//    @Select("<script>select sz_shift.* , sz_scheduling.personalId from sz_shift\n" +
//            "            left join sz_scheduling on sz_scheduling.shiftId = sz_shift.id\n" +
//            "            LEFT JOIN sz_personal on sz_personal.id = sz_scheduling.personalId\n" +
//            "            where shiftName = #{shiftName}</script>")
    SchedulingEntity findAllByShiftName(String shiftName);




}
